package com.ruoyi.web.controller.client;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.client.MesClientPages;
import com.ruoyi.system.domain.client.MesClientUsages;
import com.ruoyi.system.service.IMesClientUsagesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户端使用处Controller
 *
 * @author ruoyi
 * @date 2023-02-20
 */
@Api(value = "MesClientUsagesController", tags = "客户端使用处API")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/client/mes_client_usages" )
public class MesClientUsagesController extends BaseController {

    private final IMesClientUsagesService iMesClientUsagesService;

    /**
     * 查询客户端使用处列表
     */
    @ApiOperation(value = "查询客户端使用处列表")
    @GetMapping("/list")
    public TableDataInfo list(MesClientUsages mesClientUsages)
    {
        startPage();
        LambdaQueryWrapper<MesClientUsages> lqw = new LambdaQueryWrapper<MesClientUsages>();
        if (mesClientUsages.getClientId() != null){
            lqw.eq(MesClientUsages::getClientId ,mesClientUsages.getClientId());
        }
        if (mesClientUsages.getWorkShopId() != null){
            lqw.eq(MesClientUsages::getWorkShopId ,mesClientUsages.getWorkShopId());
        }
        if (StringUtils.isNotBlank(mesClientUsages.getStatus())){
            lqw.eq(MesClientUsages::getStatus ,mesClientUsages.getStatus());
        }
        if (StringUtils.isNotBlank(mesClientUsages.getIpAddress())){
            lqw.eq(MesClientUsages::getIpAddress ,mesClientUsages.getIpAddress());
        }
        if (StringUtils.isNotBlank(mesClientUsages.getUaUrl())){
            lqw.eq(MesClientUsages::getUaUrl ,mesClientUsages.getUaUrl());
        }
        List<MesClientUsages> list = iMesClientUsagesService.list(lqw);
        return getDataTable(list);
    }


    /**
     * 查询客户端页面列表
     */
    @ApiOperation(value = "查询页面下拉接口")
    @GetMapping("/allList")
    public AjaxResult allList(MesClientUsages mesClientUsages)
    {
        LambdaQueryWrapper<MesClientUsages> lqw = new LambdaQueryWrapper<MesClientUsages>();
        if (mesClientUsages.getClientId() != null){
            lqw.eq(MesClientUsages::getClientId ,mesClientUsages.getClientId());
        }
        if (mesClientUsages.getWorkShopId() != null){
            lqw.eq(MesClientUsages::getWorkShopId ,mesClientUsages.getWorkShopId());
        }
        if (StringUtils.isNotBlank(mesClientUsages.getStatus())){
            lqw.eq(MesClientUsages::getStatus ,mesClientUsages.getStatus());
        }
        if (StringUtils.isNotBlank(mesClientUsages.getIpAddress())){
            lqw.eq(MesClientUsages::getIpAddress ,mesClientUsages.getIpAddress());
        }
        if (StringUtils.isNotBlank(mesClientUsages.getUaUrl())){
            lqw.eq(MesClientUsages::getUaUrl ,mesClientUsages.getUaUrl());
        }
        List<MesClientUsages> list = iMesClientUsagesService.list(lqw);
        return AjaxResult.success(list);
    }
    /**
     * 导出客户端使用处列表
     */
    @Log(title = "客户端使用处" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(MesClientUsages mesClientUsages) {
        LambdaQueryWrapper<MesClientUsages> lqw = new LambdaQueryWrapper<MesClientUsages>(mesClientUsages);
        List<MesClientUsages> list = iMesClientUsagesService.list(lqw);
        ExcelUtil<MesClientUsages> util = new ExcelUtil<MesClientUsages>(MesClientUsages. class);
        return util.exportExcel(list, "mes_client_usages" );
    }

    /**
     * 获取客户端使用处详细信息
     */
    @ApiOperation(value = "获取客户端使用处详细信息")
    @GetMapping(value = "/{usageId}" )
    public AjaxResult getInfo(@PathVariable("usageId" ) Long usageId) {
        return AjaxResult.success(iMesClientUsagesService.getById(usageId));
    }

    /**
     * 新增客户端使用处
     */
    @ApiOperation(value = "新增客户端使用处")
    @Log(title = "客户端使用处" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesClientUsages mesClientUsages) {
        return toAjax(iMesClientUsagesService.save(mesClientUsages) ? 1 : 0);
    }

    /**
     * 修改客户端使用处
     */
    @ApiOperation(value = "修改客户端使用处")
    @Log(title = "客户端使用处" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesClientUsages mesClientUsages) {
        return toAjax(iMesClientUsagesService.updateById(mesClientUsages) ? 1 : 0);
    }

    /**
     * 删除客户端使用处
     */
    @ApiOperation(value = "删除客户端使用处")
    @Log(title = "客户端使用处" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{usageIds}" )
    public AjaxResult remove(@PathVariable Long[] usageIds) {
        return toAjax(iMesClientUsagesService.removeByIds(Arrays.asList(usageIds)) ? 1 : 0);
    }
}
